<?php
/**
 * Layout controller plugin
 *
 * @category    IPB_CMS
 * @package     App_Controller
 * @subpackage  Plugin
 * @copyright   Copyright (c) 2009 IPB CMS <http://ipb-cms.googlecode.com/>
 * @license     http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
 * @author      Henrique Moody <henriquemoody@gmail.com>
 */
class App_Controller_Plugin_Layout extends Zend_Controller_Plugin_Abstract
{

    /**
     * Default title
     *
     * @var string
     */
    static protected $_layoutSubTitle;

    /**
     * Called before an action is dispatched by Zend_Controller_Dispatcher
     *
     * @param Zend_Controller_Request_Abstract $request
     * @return void
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        // Logging
        Zend_Registry::get('Zend_Log')->info(__METHOD__);
        // Layout settings
        $layout = Zend_Layout::getMvcInstance();
        $view = $layout->getView();
        $view->headTitle()->setSeparator(' / ');
        // Titles
        if (null === self::$_layoutSubTitle) {
            $view->pageTitle($view->information()->getName());
            switch ($request->getModuleName()) {
                case 'admin':
                    self::$_layoutSubTitle = $view->pageTitle('Administrative Area');
                    break;
                case 'default':
                    self::$_layoutSubTitle = $view->pageTitle($view->information()->getSlogan());
                    break;
            }
            $layout->subTitle = self::$_layoutSubTitle;
        }
        // jQuery
        $view->jQuery()->setLocalPath($view->baseUrl('js/jquery-1.3.2.min.js'));
        // Stylesheet
        $stylesheet = 'style/' . $layout->getLayout() . '.css';
        $view->headLink()->prependStylesheet($view->baseUrl($stylesheet));
    }

}
